package connector;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.Properties;

public class Connection2 {
    public static void main(String[] args) {
        String driverName = "com.mysql.jdbc.Driver";
        try {
            Class<?> driverClass = Class.forName(driverName);
            Driver driver = (Driver) driverClass.newInstance();

            // step2 数据库的连接字符串
            // String url = "jdbc:mysql://localhost:3306/mysql";
            String url = "jdbc:mysql://localhost:3306/mysql?useSSL=false";

            // step3 访问数据库的账号信息
            Properties info = new Properties();
            info.setProperty("user", "root");
            info.setProperty("password", "it");

            // step4 连接到数据库
            Connection connection = driver.connect(url, info);
            System.out.println(connection);

        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | SQLException e) {
            e.printStackTrace();
        }
    }
}
